<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48" >
          <a-col :span="8" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle" >
              <a-input :max-length="255" :disabled="formDisabled" v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidNo">
              <a-input v-model="model.tenderCode" placeholder="请输入单据编号" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createBy">
              <select-user-by-dep disabled :multi="false" v-model="model.createBy"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysOrgCode">
              <j-select-depart v-model="model.sysOrgCode" :trigger-change="true" customReturnField="orgCode" :multi="true"></j-select-depart>
            </a-form-model-item>
          </a-col>
          <a-divider>基本信息</a-divider>
          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="prepareProjectId">
  <!--              <template v-if="formDisabled">-->
  <!--                <a-input disabled v-model="model.projectName"></a-input>-->
  <!--              </template>-->
  <!--              <template v-else>-->
                  <select-project-input
                    :proDisabled="proDisabled"
                    :projectStatus="'1'"
                    :disabled="formDisabled"
                    v-model="model.prepareProjectId"
                    @back="handleProjectBack"/>
  <!--              </template>-->
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
                <select-user-by-dep
                  :disabled="formDisabled"
                  v-model="model.undertaker"
                  placeholder="请选择项目承接人"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.year"
                  dictCode="yjgsnd"
                  placeholder="请选择业绩归属年度"/>
              </a-form-model-item>
            </a-col>
          </a-row>
         <a-row :gutter="40">
           <a-col :span="16">
              <a-form-model-item
                label="项目地址"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                style="height: 75px"
                >
                <a-form-model-item style="display: inline-block; width: 46%" prop="projectAddress">
                  <AddressChoice :disabled="formDisabled" v-model="model.projectAddress" ></AddressChoice>
                </a-form-model-item>
                <a-form-model-item
                  style="display: inline-block; width: 54%; padding-left: 45px" prop="detailedAddress">
                  <a-input :disabled="formDisabled" v-model="model.detailedAddress" placeholder="请输入项目详细地址"></a-input>
                </a-form-model-item>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessTeam">
                <select-team-input
                  :disabled="formDisabled"
                  v-model="model.businessTeam"
                  :tdlx="1"/>
              </a-form-model-item>
            </a-col>
         </a-row>
          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item label="报名截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entriesEndDate">
                <a-date-picker
                  show-time
                  :disabled="formDisabled"
                  placeholder="请选择报名截止时间"
                  v-model="entriesEndDate"
                  @change="(date, dateStr) => {
                    this.$set(this.model, 'entriesEndDate', dateStr);
                    this.$set(this.model, 'tenderEndDate', undefined)
                    this.tenderEndDate = undefined;
                  }"
                  :disabledDate="disabledEntriesEndDate"
                  format="YYYY-MM-DD HH:mm:ss"
                  style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="投标截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderEndDate">
                <a-date-picker
                  show-time
                  :disabled="formDisabled"
                  placeholder="请选择投标截止时间"
                  v-model="tenderEndDate"
                  @change="(date, dateStr) => { this.$set(this.model, 'tenderEndDate', dateStr) }"
                  :disabledDate="disabledTenderEndDate"
                  format="YYYY-MM-DD HH:mm:ss"
                  style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
                <select-customer-input
                  :disabled="formDisabled"
                  v-model="model.ownerUnit"
                  @change="ownerUnitChange"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item label="业主联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerLinkman">
                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.ownerLinkman"
                  :dictCode="customer_contacts"
                  placeholder="请选择联系人"
                  @input="contactsChange"
                   />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="业主联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerTel">
                <a-input :disabled="formDisabled" v-model="model.ownerTel" placeholder="请输入业主联系方式"></a-input>
              </a-form-model-item>
            </a-col>

            <a-col :span="8">
              <a-form-model-item label="招标方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingMethod">
                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.biddingMethod"
                  dictCode="bidding_method"
                  placeholder="请选择招标方式"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="40">
            <a-col :span="8">
              <a-form-model-item label="招标控制价（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="controlPrice">
                <a-input-number
                  :precision="2"
                  :disabled="formDisabled"
                  v-model="model.controlPrice"
                  placeholder="请输入招标控制价"
                  style="width: 100%"
                  :min="0"
                  :max="999999999"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="标书费（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entryFee">
                <a-input-number
                  :precision="2"
                  :disabled="formDisabled"
                  v-model="model.entryFee"
                  placeholder="请输入标书费"
                  style="width: 100%"
                  :min="0"
                  :max="999999999"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="投标保证金（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderBond">
                <a-input-number
                  :precision="2"
                  :disabled="formDisabled"
                  v-model="model.tenderBond"
                  placeholder="请输入投标保证金"
                  style="width: 100%"
                  :min="0"
                  :max="999999999"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-col :span="24">
            <a-form-model-item label="项目公示信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectPublicity">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.projectPublicity" rows="4" placeholder="请输入项目公示信息"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投标内容概要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderContent">
              <a-textarea :maxLength="500" :disabled="formDisabled" v-model="model.tenderContent" rows="4" placeholder="请输入投标内容概要"/>
            </a-form-model-item>

            <a-form-model-item label="招标文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderFile">
              <j-upload v-if="!formDisabled" :disabled="formDisabled" v-model="model.tenderFile"></j-upload>
              <a-button v-else icon="download" @click="viewFile(model.tenderFile)">文件列表</a-button>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="投标类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderType">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.tenderType"
                dictCode="tender_type"
                placeholder="请选择投标类别"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="基准分值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="baseScore">
              <a-input-number
                :disabled="formDisabled"
                v-model="model.baseScore"
                placeholder="请输入基准分值"
                :min="0"
                :max="99999"
                style="width: 100%;"/>
            </a-form-model-item>
          </a-col>

        </a-row>
          <a-divider>投标单位信息</a-divider>
          <a-row :gutter="48">
            <a-col :span="8">
              <a-form-model-item label="投标部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderDept">
                <j-select-depart  :disabled="formDisabled" v-model="model.tenderDept"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="投标编制人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderPerson">
                <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderPerson" dictCode="" placeholder="请选择投标编制人" />-->
                <select-user-by-dep :disabled="formDisabled"  :multi="false"
                                    v-model="model.tenderPerson" ></select-user-by-dep>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="投标单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderUnit">
                <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderUnit" dictCode="erp_company_files,file_name,id,del_flag = 0 and audit_status = 2" placeholder="请选择投标单位"/>-->
                <select-Company-input :disabled="formDisabled" v-model="model.tenderUnit"  />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="是否需要协调" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="needHelp">
                <j-dict-select-tag
                  @input="isTeamworkChange"
                  :disabled="formDisabled"
                  type="radio"
                  v-model="model.needHelp"
                  dictCode="YES_OR_NO"
                  placeholder="请选择是否需要协调"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item
                label="协同人员（多选）"
                v-show="model.needHelp==1"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                prop="helperIds">
                <select-user-by-dep :disabled="formDisabled"  :multi="true"
                                    v-model="model.helperIds" ></select-user-by-dep>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
                <a-textarea :maxLength="500" :disabled="formDisabled" v-model="model.remarks" rows="4" placeholder="备注"/>
              </a-form-model-item>
            </a-col>
          <!--          业务分类-->
            <a-divider>业务分类</a-divider>
          <a-col :span="24">
            <div style="margin-bottom: 6px;margin-top: 6px">
              <a-button @click="handleAdd" v-if="!formDisabled" type="primary">新增</a-button>
            </div>
            <a-table
              ref="table"
              size="middle"
              rowKey="id"
              :loading="loading"
              :columns="columns"
              :pagination="false"
              :data-source="dataSource">
              <span slot="action" slot-scope="text, record">
                <template v-if="!formDisabled">
                  <a @click="handleEdit(record)">编辑</a>
                  <a-divider type="vertical"/>
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </template>
              </span>
            </a-table>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
        <!--投标文件信息 -->
        <template v-if="formDisabled">
          <a-divider>投标文件信息</a-divider>
          <a-row :gutter="48">
            <a-col :span="24">
              <a-table
                ref="table"
                size="middle"
                rowKey="id"
                :loading="fileLoading"
                :columns="fileColumns"
                :pagination="fileIpagination"
                :data-source="fileDataSource">
              </a-table>
            </a-col>
          </a-row>
        </template>
        <!--投标结果信息 -->
        <template v-if="formDisabled">
          <a-divider>投标结果信息</a-divider>
          <a-row :gutter="48">
            <a-col :span="24">
              <a-table
                ref="table"
                size="middle"
                rowKey="id"
                :loading="resLoading"
                :columns="resColumns"
                :pagination="resIpagination"
                :data-source="resDataSource">
              </a-table>
            </a-col>
          </a-row>
        </template>
      </a-form-model>
      <view-file-modal ref="viewFileModal"></view-file-modal>
      <erp-omc-tender-service-modal ref="itemList" @ok="modalFormOk"></erp-omc-tender-service-modal>
    </j-form-container>
  </a-spin>
</template>

<script>

import { getAction, httpAction } from '@/api/manage'
import { viewFile } from '@/utils/util'
import moment from 'moment'
import { mapGetters } from 'vuex'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import ViewFileModal from '@/views/scy/components/ViewFileModal'
import { filterMultiDictText, initDictOptions } from '@comp/dict/JDictSelectUtil';
import ErpOmcTenderServiceModal from '@/views/erp/omc/tender/modules/ErpOmcTenderServiceModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin';
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import SelectProjectInput from '@/views/scy/components/SelectProjectInput';
import JSelectDepart from '../../../../../components/jeecgbiz/JSelectDepart';
import AddressChoice from '@/components/AddressChoice/AddressChoice';
export default {
  name: 'ErpOmcTenderForm',
  mixins: [JeecgBpmListMixin,DisabledAuthFilterMixin, viewFile],
  components: {
    JSelectDepart,
    ViewFileModal,
    SelectUserByDep,
    SelectTeamInput,
    SelectCustomerInput,
    ErpOmcTenderServiceModal,
    SelectProjectInput,
    AddressChoice
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  watch: {
    activeKey(key) {
      this.$forceUpdate()
    }
  },
  data() {
    return {
      activeKey: ['1', '2', '3', '4'],
      loading: false,
      //unitLoading: false,
      fileLoading: false,
      resLoading: false,
      fileColumns: [
        {
          title: '投标文件编号',
          align: 'center',
          dataIndex: 'bidNo',
          ellipsis: true,
        },
        {
          title: '难度系数',
          align: 'center',
          dataIndex: 'difficultyCoefficient',
          ellipsis: true,
        },
        {
          title: '标书费（元）',
          align: 'center',
          dataIndex: 'bidFee',
          ellipsis: true,
        },
        {
          title: '投标单位',
          align: 'center',
          dataIndex: 'tenderUnitId_dictText',
          ellipsis: true,
        },
        {
          title: '投标部门',
          align: 'center',
          dataIndex: 'tenderDept_dictText',
          ellipsis: true,
        },
        {
          title: '投标金额（元）',
          align: 'center',
          dataIndex: 'tenderAmount',
          ellipsis: true,
        },
        {
          title: '开标方式',
          align: 'center',
          dataIndex: 'bidMethod_dictText',
          ellipsis: true,
        },
        {
          title: '文件类型',
          align: 'center',
          dataIndex: 'fileType_dictText',
          ellipsis: true,
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
        }
      ],
      resColumns: [
        {
          title: '投标结果编号',
          align: 'center',
          dataIndex: 'bidResultNo',
          ellipsis: true,
        },
        {
          title: '开标日期',
          align: 'center',
          dataIndex: 'bidOpeningData',
          ellipsis: true,
        },
        {
          title: '中标结果',
          align: 'center',
          dataIndex: 'bidResult_dictText',
          ellipsis: true,
        },
        {
          title: '投标金额（元）',
          align: 'center',
          dataIndex: 'tenderAmount',
          ellipsis: true,
        },
        // {
        //   title: '投标部门',
        //   align: 'center',
        //   dataIndex: 'bidResult_dictText'
        // },
        {
          title: '投标单位',
          align: 'center',
          dataIndex: 'tenderUnit_dictText',
          ellipsis: true,
        },
        {
          title: '招标代理费（元）',
          align: 'center',
          dataIndex: 'agentFee',
          ellipsis: true,
        },
        {
          title: '履约保证金（元）',
          align: 'center',
          dataIndex: 'bail',
          ellipsis: true,
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],

      dataSource: [],
      fileDataSource: [],
      resDataSource: [],
      /* 分页参数 */
      fileIpagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      /* 分页参数 */
      resIpagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      isShowTeamwork: false,
      model: {
        handlerName: ''
      },
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      dictOptions: {},
      confirmLoading: false,
      validatorRules: {
        prepareProjectId: [
          { required: true, message: '请选择预立项项目!' }
        ],
        undertaker: [
          { required: true, message: '请选择承接人!' }
        ],
        year: [
          { required: true, message: '请选择业绩归属年度!' }
        ],
        projectAddress: [
          { required: true, message: '请选择项目地址!' }
        ],
        detailedAddress: [
          { required: true, message: '请输入项目详细地址!' }
        ],
        businessTeam: [
          { required: true, message: '请选择经营团队!' }
        ],
        // TASK#1949非必填
        // entriesEndDate: [
        //   { required: true, message: '请选择报名截止日期!' }
        // ],
        // tenderEndDate: [
        //   { required: true, message: '请选择投标截止日期!' }
        // ],
        ownerUnit: [
          { required: true, message: '请选择业主单位!' }
        ],
        ownerLinkman: [
          { required: true, message: '请选择业主联系人!' }
        ],
        ownerTel: [
          { required: true, message: '请输入业主联系方式!' },
          { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的联系方式!' }
        ],
        // TASK#1949非必填
        // biddingMethod: [
        //   { required: true, message: '请选择招标方式!' }
        // ],
        controlPrice: [
          { required: false },
          { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        entryFee: [
          { required: false },
          { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        tenderBond: [
          { required: false },
          { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        baseScore: [
          { required: false },
          { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!' }
        ]
      },
      url: {
        add: '/api/erp/omc/tender/erpOmcTender/add',
        edit: '/api/erp/omc/tender/erpOmcTender/edit',
        queryById: '/api/erp/omc/tender/erpOmcTender/queryById',
        queryPrepareProjectById: '/api/erp/omc/prepareproject/erpOmcPrepareProject/queryById',
        queryTenderServiceListByTenderId: '/api/erp/omc/tender/erpOmcTenderService/queryTenderServiceListByTenderId',
        queryOmcTenderFileList: '/api/erp/omc/tenderfile/erpOmcTenderFile/list',
        queryOmcTenderResultList: '/api/erp/omc/tenderresult/erpOmcTenderResult/list'
      },
      customer_contacts: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0',
      sutdata: '',
      entriesEndDate: undefined,
      tenderEndDate: undefined
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    proDisabled() {
        return true
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
    this.initDictConfig();
  },
  mounted() {
  },
  methods: {
    initDictConfig() {
      // initDictOptions('erp_company_files,file_name,id, del_flag=0 and audit_status = 2').then((res) => {
      //   if (res.success) {
      //     this.$set(this.dictOptions, 'tenderUnit', res.result)
      //   }
      // })
      initDictOptions('erp_company_files,file_name,id ').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderUnit', res.result)
        }
      })
      initDictOptions('sys_depart,depart_name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderDept', res.result)
        }
      })
      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderPerson', res.result)
        }
      })
    },

    handleAdd() {
      this.$refs.itemList.add();
      this.$refs.itemList.title = '新增';
      this.$refs.itemList.disableSubmit = false;
    },
    handleEdit(record) {
      this.$refs.itemList.edit(record);
      this.$refs.itemList.title = '修改';
      this.$refs.itemList.disableSubmit = false;
    },
    handleDelete(id) {
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == id) {
          this.dataSource.splice(i, 1);
        }
      }
    },
    modalFormOk(data) {
      this.loading = true;
      let flag = true;
      // debugger;
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == data.id) {
          this.dataSource.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.dataSource.push(data);
      }
      this.loading = false;
    },
    // 是否协同
    isTeamworkChange(e) {
      if (e == '1') {
        this.isShowTeamwork = true
      } else {
        this.isShowTeamwork = false
      }
    },
    // 业主单位
    ownerUnitChange() {
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
      this.$set(this.model, 'ownerLinkman', undefined)
      this.$set(this.model, 'ownerTel', undefined)
    },
    // 业主联系人
    contactsChange(val) {
      this.$set(this.model, 'ownerLinkman', val)
      getAction('/api/erp/omc/customermanager/erpOmcCustomerManagerContact/queryById', { id: val }).then((res) => {
        if (res.success) {
          let data = res.result.records || res.result
          this.$set(this.model, 'ownerTel', data.lxfs)
        }
      })
    },
    // 选择预立项
    choosePrepareProjectChange(e) {
      if (e) {
        let params = { id: e };
        getAction(this.url.queryPrepareProjectById, params).then((res) => {
          if (res.success) {
            if (res.result) {
              this.model.projectName = res.result.mc
              this.model.projectType = res.result.xmlx
              this.model.undertaker = res.result.cjr
              this.model.year = res.result.yjgsnd
              this.model.businessTeam = res.result.ywtd
              this.model.ownerUnit = res.result.yzdw
              this.model.ownerLinkman = res.result.lxr
              this.model.ownerTel = res.result.lxdh
              this.model.projectAddress = res.result.ssq
              this.dataSource = res.result.serviceList;
              this.model = Object.assign({}, this.model);
            }
          }
        });
      }
    },
    ...mapGetters(['userInfo']),
    add(value) {
      this.dataSource = []
      this.edit(this.modelDefault);
      this.model.tenderCode = value.tenderCode;
      this.model.proposer = value.loginUser.empId;
      this.model.proposerDeptId = this.userInfo().deptId;
      this.model.isTeamwork = 0;
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
      this.entriesEndDate = undefined;
      this.tenderEndDate = undefined;
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.isShowTeamwork = this.model.isTeamwork === '1'
      this.entriesEndDate = this.model.entriesEndDate;
      this.tenderEndDate = this.model.tenderEndDate;
      if (this.model.id) {
        // eslint-disable-next-line no-unused-expressions
        getAction(this.url.queryTenderServiceListByTenderId, { id: this.model.id }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
          }
        }),

        getAction(this.url.queryOmcTenderFileList, { tenderId: this.model.id }).then((res) => {
          if (res.success) {
            this.fileDataSource = res.result.records || res.result
            this.fileIpagination.total = res.result.total;
          }
        }),
        getAction(this.url.queryOmcTenderResultList, { tenderId: this.model.id }).then((res) => {
          if (res.success) {
            this.resDataSource = res.result.records || res.result
            this.resIpagination.total = res.result.total
          }
        })
      }
      this.visible = true;
    },
    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId };
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          this.model.itemList = this.dataSource;
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        } else {
          that.$emit('unButtonDisable');
        }
      })
    },
    handleProjectBack(project) {
      this.$set(this.model, 'prepareProjectId', project[0].id)
      this.$set(this.model, 'projectName', project[0].projectName)
      this.$set(this.model, 'undertaker', project[0].undertaker)
      this.$set(this.model, 'year', project[0].year)
      this.$set(this.model, 'projectAddress', project[0].areaCode)
      this.$set(this.model, 'detailedAddress', project[0].projectAddress)
      this.$set(this.model, 'businessTeam', project[0].teamName)
      this.$set(this.model, 'ownerUnit', project[0].ownerUnit)
      this.$set(this.model, 'ownerLinkman', project[0].contacts)
      this.$set(this.model, 'ownerTel', project[0].contactTel)
    },
    disabledEntriesEndDate(currentDate) {
      return currentDate < moment(this.model.createTime).subtract('day')
    },
    disabledTenderEndDate(currentDate) {
      return currentDate < moment(this.model.entriesEndDate).subtract('day')
    }
  }
}
</script>
<style scoped>
.ant-divider {
  font-size: 10px;
  font-weight: bold;
}

/*.ant-tabs{
  width: 850px;
}*/
.ant-row{
  margin: 0 !important;
}
</style>
